<?php
/**
* @version 1.0.0
* @package RSSearch! 1.0.0
* @copyright (C) 2011 www.rsjoomla.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/
defined('_JEXEC') or die('Restricted access');
class JElementContentsearchfields extends JElement{
	var $_name = 'Contentsearchfields';

	function fetchElement($name, $value, &$node, $control_name)
	{
		
		$search_fields = array(
			'content' 		=> 'Content',
			'categories'	=> 'Categories',
			'sections' 		=> 'Sections'
		);

		$result = '<script type="text/javascript">
			function listcategories(checked){
				if(checked == true){
					document.getElementById("listcategories").style.visibility="visible";
					document.getElementById("desc_categories").style.visibility="hidden";
				}else {
					document.getElementById("listcategories").style.visibility="hidden";
					document.getElementById("desc_categories").style.visibility="visible";
				}
			}
			function listsections(checked){
				if(checked == true){
					document.getElementById("listsections").style.visibility="visible";
					document.getElementById("desc_sections").style.visibility="hidden";
				}else {
					document.getElementById("listsections").style.visibility="hidden";
					document.getElementById("desc_sections").style.visibility="visible";
				}
			}

			function listcontent(checked){}
		</script>';

		foreach( $search_fields as $component => $component_name){
			if(is_array( $value) ) {
			
				if( in_array( $component, $value ) ) {
					$result .= '<label><input checked="checked" type="checkbox" name="'.$control_name.'['.$name.'][]" value="'.$component.'" onclick="list'.$component.'(this.checked);" id="'.$component.'_btn" /> '.$component_name.'</label>';
				} else {
					$result .= '<label><input type="checkbox" name="'.$control_name.'['.$name.'][]" value="'.$component.'" onclick="list'.$component.'(this.checked);" id="'.$component.'_btn" /> '.$component_name.'</label>';
				}
			} elseif ( $value ) {
				if( $value == $component) {
					$result .= '<label><input checked="checked" type="checkbox" name="'.$control_name.'['.$name.'][]" value="'.$component.'" onclick="list'.$component.'(this.checked);" id="'.$component.'_btn" /> '.$component_name.'</label>';
				} else {
					$result .= '<label><input type="checkbox" name="'.$control_name.'['.$name.'][]" value="'.$component.'" onclick="list'.$component.'(this.checked);" id="'.$component.'_btn" /> '.$component_name.'</label>';
				}
			} elseif ( !( $value ) ) {
				$result .= '<label><input type="checkbox" name="'.$control_name.'['.$name.'][]" value="'.$component.'" onclick="list'.$component.'(this.checked);" id="'.$component.'_btn" />'.$component_name.'</label>';
			}
		}

		return $result;
	}
}
?>